import os
import typing
from pydantic_settings import BaseSettings
from fastapi import FastAPI, Request

class Settings(BaseSettings):
    VERSION: str = "0.1.0"
    APP_TITLE: str = "企业贷款平台系统"
    PROJECT_NAME: str = "企业贷款平台系统"
    APP_DESCRIPTION: str = "企业贷款平台系统"
    APP_IP: str = "http://daikuan.yanjin.pro/"

    CORS_ORIGINS: typing.List = ["*"]
    CORS_ALLOW_CREDENTIALS: bool = True
    CORS_ALLOW_METHODS: typing.List = ["*"]
    CORS_ALLOW_HEADERS: typing.List = ["*"]

    DEBUG: bool = True
    LOG_DIR: str = "app/log/logs"
    PROJECT_ROOT: str = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    BASE_DIR: str = os.path.abspath(os.path.join(PROJECT_ROOT, os.pardir))
    LOGS_ROOT: str = os.path.join(BASE_DIR, "app/log")
    SECRET_KEY: str = "3488a63e1765035d386f05409663f55c83bfae3b3c61a932744b20ad14244dcf"  # openssl rand -hex 32
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7000  # 7 day
    TORTOISE_ORM: dict = {
        "connections": {
            "mysql": {
                'engine': 'tortoise.backends.mysql',
                "credentials": {
                    "host": "sywdata.mysql.polardb.rds.aliyuncs.com",
                    "port": "3306",
                    "user": "syw",
                    "password": "y9gC8A6mquRX45P4%UDO!",
                    "database": "daikuan",
                },
            }
        },
        "apps": {
            "models": {
                "models": ["app.models", "aerich.models"],
                "default_connection": "mysql",
            },
        },
        "use_tz": False,
        "timezone": "Asia/Shanghai",
    }
    REDIS:str = "redis://localhost:6379/5"
    DATETIME_FORMAT: str = "%Y-%m-%d %H:%M:%S"
    DATE_FORMAT: str = "%Y-%m-%d"
    ALLOWED_IMAGES: typing.List = ['png', 'jpg', 'jpeg', 'gif','webp']
    ALLOWED_EXTENSIONS: typing.List = ['png', 'jpg', 'jpeg', 'gif', 'mp3', 'mp4', 'xlsx', 'xls', 'csv', 'pdf', 'doc', 'docx','webp']
    UPLOAD_FOLDER:str = "app/upload"
    EXCEL_FOLDER:str = "app/upload/excel"

    JOBS_TYPE: typing.List = ['', '循环任务', '定时任务']
    CUSTOMERS_TYPE:typing.List = [""]
    CUSTOMERS_STATUS: typing.List = ['待处理', '已处理']


settings = Settings()
